import { createOrder } from '@/api/order'

export default {
    // ...其他代码
    methods: {
        // 提交订单
        async submitOrder() {
            try {
                const orderData = {
                    products: this.cartItems.map(item => ({
                        productId: item.id,
                        quantity: item.quantity,
                        price: item.price
                    })),
                    totalAmount: this.totalAmount
                }
                
                const res = await createOrder(orderData)
                if (res.code === 200) {
                    // 清空购物车
                    this.$store.commit('cart/CLEAR_CART')
                    this.$message.success('订单创建成功')
                    // 跳转到订单列表
                    this.$router.push('/order')
                }
            } catch (error) {
                this.$message.error('创建订单失败：' + error.message)
            }
        }
    }
} 